﻿using Xejen.Ipc.Framework.Flows;
using System;
using System.Collections.Generic;
using System.Text;

namespace Xejen.Ipc.Framework.Flows
{
    /// <inheritdoc cref="IFlowInstance"/>
    /// <typeparam name="TData"><inheritdoc cref="IFlow{TData}" path="/typeparam[@name='TData']"/></typeparam>
    internal class FlowInstance<TData> : IFlowInstance
        where TData : new()
    {
        /// <inheritdoc/>
        public int Id { get; set; }
        /// <inheritdoc/>
        public string Name { get; set; }
        /// <inheritdoc/>
        public IFlowInstance Parent { get; set; }
        /// <inheritdoc/>
        public FlowStatus Status { get; set; }

        /// <inheritdoc/>
        public DateTime? CycleStartTime { get; set; }
        /// <inheritdoc/>
        public DateTime? CycleEndTime { get; set; }
        /// <inheritdoc/>
        public TimeSpan? CycleExecutionTime { get; set; }

        /// <inheritdoc cref="FlowInstance{TData}"/>
        /// <param name="flow"><inheritdoc cref="IFlow{TData}" path="/summary"/></param>
        /// <param name="parent">父流程</param>
        public FlowInstance(IFlow<TData> flow, IFlow<TData> parent = null)
        {
            Check.NotNull(flow, nameof(flow));

            Id = flow.Id;
            Name = flow.Name;
            Status = flow.Status;
            if (parent != null)
            {
                Parent = new FlowInstance<TData>(parent);
            }
        }
    }
}
